package gitee.blacol.myIdUtil.entity.util;

import gitee.blacol.myIdUtil.enums.PropType;

import java.lang.reflect.Field;
import java.util.Date;

public class ValueUtil {
    public static Object getValue(Object obj, String key, PropType type) throws NoSuchFieldException, IllegalAccessException {
        Field field = obj.getClass().getDeclaredField(key);
        field.setAccessible(true);
        Object o = field.get(obj);
        switch (type){
            case INTEGER:
                return Integer.valueOf(o.toString());
            case DOUBLE:
                return Double.valueOf(o.toString());
            case STRING:
                return o.toString();
            case DATE:
                return (Date) o;
            default:
                return null;
        }
    }
}
